	<script>
	$(function() {

		$('#_duration').change(function() {
			filter_report();
		});

		$('#_unitPatientLocation').change(function() {
			filter_report();
		});

		$('#_physician').change(function() {
			filter_report();
		});

		$('#_physicianGroup').change(function() {
			filter_report();
		});

		$('#_pharmacist').change(function() {
			filter_report();
		});

		 $('#_optPhysician').click(function(){
			 	$('#_physicianGroup').attr("disabled", true);
			 	$('#_physician').attr("disabled", false);
			 	filter_report();
			 });

		 $('#_optPhysicianGroup').click(function(){
			 	$('#_physicianGroup').attr("disabled", false);
			 	$('#_physician').attr("disabled", true);
			 	filter_report();
			 });
	
		// set effect from select menu value
		$( "#_button" ).click(function() {
			var button	=	document.getElementById('_button');
			var buttonText	=	(button.innerHTML);
			if (buttonText	==	'Hide Filter')
			{
				$( ".filter-div" ).hide( "blind");
				button.innerHTML	=	'Show Filter';
			} 
			else
			{
				$( ".filter-div" ).show( "blind");
				button.innerHTML	=	'Hide Filter';
			} 
			return false;
		});

		$('#_physicianGroup').attr("disabled", true);

	});

	function filter_report()
	{
		var filter_url = '';
		var active_filter_text	=	'';
		if ($('#_duration').val() != -1)
		{
			filter_url	= filter_url + '/duration/' + $('#_duration').val();
			active_filter_text = active_filter_text + '<b>Duration:  </b>' + $('#_duration option:selected').text() + '  ';
		}

		if ($('#_unitPatientLocation').val() != -1)
		{
			filter_url	= filter_url + '/upl/' + $('#_unitPatientLocation').val();
			active_filter_text = active_filter_text + '<b>Unit/Patient Location:  </b>' + $('#_unitPatientLocation option:selected').text() + '  ';
		}
			
		if (!$('#_physician').attr("disabled") && $('#_physician').val() != -1)
		{
			filter_url	= filter_url + '/physician/' + $('#_physician').val();
			active_filter_text = active_filter_text + '<b>Physician:  </b>' + $('#_physician option:selected').text() + '  ';
		}
			
		if (!$('#_physicianGroup').attr("disabled") && $('#_physicianGroup').val() != -1)
		{
			filter_url	= filter_url + '/pgroup/' + $('#_physicianGroup').val();
			active_filter_text = active_filter_text + '<b>Physician Group:  </b>' + $('#_physicianGroup option:selected').text() + '  ';
		}
			
		if ($('#_pharmacist').val() != -1)
		{
			filter_url	= filter_url + '/pharmacist/' + $('#_pharmacist').val();
			active_filter_text = active_filter_text + '<b>Pharmacist:  </b>' + $('#_pharmacist option:selected').text() + '  ';
		}

		active_filter_text = '<b><u>Active Filter</u>:  </b>' + (active_filter_text == '' ? 'None' : active_filter_text); 

		var currentFilter	=	$('#_activeFilterText').html();
		//window.alert(active_filter_text);
		
		if (active_filter_text	==	currentFilter)
			return true; //No change to filter made


			$('#_activeFilterText').html('Loading new data...');
			$('#_tableForCounts').html('');
			$('#_tableForSavings').html('');
			$('#_chartForCounts').html('');
			$('#_chartForSavings').html('');
			
		
		//window.alert(filter_url);

		var dateTicks = String(Number(new Date())); //Must append Date Ticks as a segment to the URL so IE wont' cache the Ajax link
		//window.alert(my_url() + '/report/intervention_report_update/' + dateTicks + filter_url);
		returnedData = $.ajax({
		      url: my_url() + '/report/intervention_report_update/' + dateTicks + filter_url,
		      global: false,
		      dataType: 'html',
		      async:false
		   }
		).responseText;
		//window.alert(returnedData);
		tableArray	=	returnedData.split('|');
		//window.alert(tableArray[2].replace(/_DELIM_/g,'|'));
		$('#_tableForCounts').html(tableArray[0]);
		$('#_tableForSavings').html(tableArray[1]);
		$('#_activeFilterText').html(active_filter_text);
		//Don't load empty grids
		if (tableArray[2].replace(/_DELIM_/g,'|')	!=	'')
		{
			$('#_chartForCounts').html('<img src="' + tableArray[2].replace(/_DELIM_/g,'|') + '" />');
			$('#_chartForSavings').html('<img src="' + tableArray[3].replace(/_DELIM_/g,'|') + '" />');
		}
		return true;
	}

	function my_url()
	{
		return '<?php echo site_url(); //Needed to reference website from javascript?>';
	}
	</script>
<p>
	<button id="_button" type="button">Show Filter</button>
	<div class="filter-div" style="display: none;">
		<h3>Filter</h3>
		<?php echo form_label('Duration:', '_duration');?>
		<?php echo form_dropdown('duration', $duration_list, '', 'id="_duration" ');?>
		<br class="clear" />
		
		<?php echo form_label('Unit/Patient Location:', '_unitPatientLocation');?>
		<?php echo form_dropdown('unit_patient_location', $unit_patient_location_list, '', 'id="_unitPatientLocation" ');?>		
		<br class="clear" />
		
		<?php 	$p_opt	= form_label('Physician:', '_physician').form_dropdown('physician', $physician_list, '', 'id="_physician" ');
				echo form_radio($opt_physician, 'accept','TRUE').$p_opt.'<br>';
				?>		
		<br class="clear" />
		<?php 	$pg_opt	= form_label('Physician Group:', '_physicianGroup').form_dropdown('physician_group', $physician_group_list, '-1', 'id="_physicianGroup" ');
				echo form_radio($opt_physician_group, 'accept','').$pg_opt.'<br>';
				?>		
				
		<br class="clear" />
		
		<?php echo form_label('Pharmacist:', '_pharmacist');?>
		<?php echo form_dropdown('pharmacist', $pharmacist_list, '-1', 'id="_pharmacist" ');?>		
		<br class="clear" />
		<h3>&nbsp;</h3>
	</div>
	
</p>
<p>
	<div id="_activeFilterText">
		<b><u>Active Filter</u>:</b>&nbsp;&nbsp;None
	</div>
</p>
<p>
	<div id="_tableForCounts" style="width: 530px; float:left;margin-right:15px;">
		<?php  echo $table_for_counts;?>
	</div>
	<div id="_chartForCounts">
		<?php  echo $google_chart_count_url	==	'' ? '' : '<img src="'.$google_chart_count_url.'" alt="Intervention Count Chart"/>';?>
	</div>
	<br class="clear" />
</p>
<p>
	<div id="_tableForSavings" style="width: 400px; float:left;margin-right:15px;">
		<?php  echo $table_for_savings;?>
	</div>
	<div id="_chartForSavings">
		<?php  echo $google_chart_savings_url == '' ? '' : '<img src="'.$google_chart_savings_url.'" alt="Intervention Count Chart"/>';?>
	</div>
	<br class="clear" />
</p>

